﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using _MetalSlug.Mission;
using System.Xml;
using System.IO;

namespace _MetalSlug.Mementoes
{
    public class CareTaker
    {
        public const String PathFile = "SaveGame.xml";
        static CareTaker Instance;
        MissionMemento Mission;

        public static CareTaker GetInstance()
        {
            if(Instance == null)
            {
                Instance = new CareTaker();
            }
            return Instance;
        }

        private CareTaker()
        {
            if (Mission == null && File.Exists(PathFile))
            {
                InitalFromFile();
            }
        }


        public void CreateMissionMemento(MyMission RepresentMission, int GameCore)
        {
            Mission = new MissionMemento(RepresentMission,GameCore);
        }

        public void InitalFromFile()
        {
            XmlDocument Doc = new XmlDocument();
            Doc.Load(PathFile);
            Mission = new MissionMemento(Doc.DocumentElement);
        }

        public void SaveGameToFile()
        {
            XmlDocument Document = new XmlDocument();
            XmlElement eleMission = Mission.ToXML(Document);
            Document.AppendChild(eleMission);
            Document.Save(PathFile);
        }

        public Boolean IsNull()
        {
            return Mission == null;
        }

        public MissionMemento GetMissionMemento()
        {
            return Mission;
        }

        public IMemento GetEnemyMemento(int ID)
        {
            return Mission.GetEnemyMemento(ID);
        }

        public IMemento GetMapMemento()
        {
            return Mission.Map;
        }

        public HeroMemento GetHeroMemento()
        {
            return Mission.Hero;
        }
    }
}
